package com.tony.juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: AutomicDemo002
 * @Auther: 皮蛋布丁
 * @Date: 2022/04/04/19:57
 * @Description: 基础类型原子操作类
 */
public class AutomicDemo002 {

    public static void main(String[] args) throws InterruptedException {

        /*AtomicLong num = new AtomicLong(0); //实例化原子类对象
        for (int i = 0; i < 3; i++) {
            new Thread(()->{
                System.out.printf("【%s】数据的加法计算：%d %n", Thread.currentThread().getName(), num.addAndGet(100));
            }).start();
        }
        TimeUnit.SECONDS.sleep(2);
        System.out.println("【计算完成】最终的计算结果为：" + num);*/


        AtomicLong num = new AtomicLong(100L); // 实例化原子类对象
        System.err.println("【×原子数据修改】数据修改的结果：" + num.compareAndSet(200L, 300L));
        System.err.println("【×原子数据获取】新的数据内容：" + num.get());
        System.out.println("【√原子数据修改】数据修改的结果：" + num.compareAndSet(100L, 300L));
        System.out.println("【√原子数据获取】新的数据内容：" + num.get());


    }

}
